
use gfsc::*;
use clap::Parser;
use dirs::home_dir;

//type Result<T> = anyhow::Result<T>;

#[derive(Parser, Debug)]
#[clap(
    name = "gfs sendfile",
    version,
    author,
    about = "upload file to gfs with gfsc"
)]
struct Cli {
    /// 
    #[clap(name = "file",  default_value = "")]    
    file: String,
    /// Sets a router.json
    #[clap(name = "router", short, long, default_value = "~/.rabbit/router.json")]    
    router: String,
}

pub fn main() {

    let mut cli = Cli::parse();
    if cli.router.as_str().eq("~/.rabbit/router.json"){        
        let home =  home_dir().unwrap();
        cli.router = home.join(".rabbit").join("router.json").display().to_string();
    }
    // let filename = std::env::args().nth(1).expect("no file given");      
    println!("{:#?}", cli);
 
    let router = gfsc_new_router( &cli.router ).unwrap();    
    let f = gfsc_write_file(&router,  &cli.file );
    let rt = tokio::runtime::Runtime::new().unwrap();
    let r = rt.block_on(f);
    println!("{:#?}", r);

}
 